//
//  TerminalTypeTableViewCell.m
//  OutesIOS
//
//  Created by norman on 2018/12/9.
//  Copyright © 2018 norman. All rights reserved.
//

#import "TerminalTypeTableViewCell.h"
#import "CheckBoxView.h"

@interface TerminalTypeTableViewCell()

@property (nonatomic,strong)CheckBoxView *box1;
@property (nonatomic,strong)CheckBoxView *box2;

@end


@implementation TerminalTypeTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupViews];
    }
    return self;
}

- (void)setupViews {
    self.contentView.width = kScreen_Width - CELL_PADDING_RIGTH_AND_IMAGE;
    //标题
    UILabel *lb = [UILabel labelSingleLineFontSize:kListTitleFontSize content:@"末端类型"];
    lb.x = CELL_PADDING_LEFT;
    lb.y = CELL_PADDING_TOP;
    lb.textColor = CM_TABLE_TITLE_COLOR;
    [self.contentView addSubview:lb];
    //设置cell的高度
    self.contentView.height = CGRectGetMaxY(lb.frame) + CELL_PADDING_BOTTOM;
    
    CheckBoxView *box1 = [[CheckBoxView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(lb.frame) + 30, 0, 110, self.contentView.height)];
    box1.statusChanged = ^(BOOL isChecked) {
        NSString *data;
        if (isChecked) {
            if (self.box2.isSelected) {
                data = @"风机盘管+地暖";
            } else {
                data = @"风机盘管";
            }
        } else {
            if (self.box2.isSelected) {
                data = @"地暖";
            } else {
                data = @"";
            }
        }
        if (self.checkBoxSelectionChanged) {
            self.checkBoxSelectionChanged(data);
        }
    };
    self.box1 = box1;
    [self.contentView addSubview:box1];
    
    CheckBoxView *box2 = [[CheckBoxView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(box1.frame), 0, 90, self.contentView.height)];
    box2.statusChanged = ^(BOOL isChecked) {
        NSString *data;
        if (isChecked) {
            if (self.box1.isSelected) {
                data = @"风机盘管+地暖";
            } else {
                data = @"地暖";
            }
        } else {
            if (self.box1.isSelected) {
                data = @"风机盘管";
            } else {
                data = @"";
            }
        }
        if (self.checkBoxSelectionChanged) {
            self.checkBoxSelectionChanged(data);
        }
    };
    self.box2 = box2;
    [self.contentView addSubview:box2];
}

- (void)setCheckBoxStatus:(NSString *)data {
    BOOL status = NO;
    if (![Tools isEmpty:data]
        &&[data containsString:@"风机盘管"]) {
        status = YES;
    }
    [self.box1 setCheckBoxTitle:@"风机盘管" andStatus:status];
    status = NO;
    if (![Tools isEmpty:data]
        &&[data containsString:@"地暖"]) {
        status = YES;
    }
    [self.box2 setCheckBoxTitle:@"地暖" andStatus:status];
}

- (CGFloat)cellHeight {
    return self.contentView.height;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
